package cn.xpf.study.controller;

import cn.xpf.study.dao.LessonMapper;
import cn.xpf.study.model.Lesson;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Create on 2021/5/13
 *
 * @author shuxinsheng@qiyi.com
 **/
@RequestMapping("/")
@Controller
public class AppController {

    @Autowired
    LessonMapper lessonMapper;

    @RequestMapping("/index")
    public String index(Model model, HttpSession httpSession) {
        Object username = httpSession.getAttribute("username");
        model.addAttribute("username", username);
        List<Lesson> lessonList = lessonMapper.findAll();
        model.addAttribute("lessonList", lessonList);
//        return "index";
        return "index_demo";
    }


    @RequestMapping("/hello")
    @ResponseBody
    public String say() {
        int count = lessonMapper.count();
        System.out.println(count);
        System.out.println("Hello springboot");
        return "hello,this is a springboot demo！~";
    }

}
